/**
 * 构建修改用户基本信息任务
 * @param user
 * @returns {Promise<any>}
 */
export function buildEditUserTask( user, _this ){
    return new Promise(function(resolve, reject) {
        _this.axios.request({
            method: "put",
            url: "./kwp/kdi/user/" + user.uuid,
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            },
            data: {
                name: user.name,
                sex: user.sex,
                enabledTime: user.enabledTime,
                expiryTime: user.expiryTime
            }
        }).then(response => {
            resolve(response);
        }).catch(error => {
            reject(error);
        });
    });
}

/**
 * 构建修改用户账号任务
 * @param mt
 * @param user
 * @param qs
 * @returns {Promise<any>}
 */
export function buildEditAccountTask( mt, user, _this ){
    return new Promise(function(resolve, reject) {
        let headers = {};
        let url = "./kwp/kdi/vouer/" + user.accUuid;
        let data = {code: user.accCode,vou: "Account"};
        if( mt === "post" ){
            headers = {"Content-Type": "application/x-www-form-urlencoded"};
            url = "./kwp/kdi/user/" + user.uuid + "/vouer";
            data = _this.qs.stringify(data);
        }else if ( mt === "put" ) {
            headers = {"Content-Type": "application/json;charset=UTF-8"};
        }else if ( mt === "delete" ) {
            headers = {};
        }else{
            return;
        }
        _this.axios.request({
            method: mt,
            url: url,
            headers: headers,
            data: data
        }).then(response => {
            resolve(response);
        }).catch(error => {
            reject(error);
        });
    });
}

/**
 * 构建修改用户工号任务
 * @param mt
 * @param user
 * @param qs
 * @returns {Promise<any>}
 */
export function buildEditJobTask( mt, user, _this ){
    return new Promise(function(resolve, reject) {
        let headers = {};
        let url = "./kwp/kdi/vouer/" + user.jobUuid;
        let data = {code: user.jobCode,vou: "JobCode"};
        if( mt === "post" ){
            headers = {"Content-Type": "application/x-www-form-urlencoded"};
            url = "./kwp/kdi/user/" + user.uuid + "/vouer";
            data = _this.qs.stringify(data);
        }else if ( mt === "put" ) {
            headers = {"Content-Type": "application/json;charset=UTF-8"};
        }else if ( mt === "delete" ) {
            headers = {};
        }else{
            return;
        }
        _this.axios.request({
            method: mt,
            url: url,
            headers: headers,
            data: data
        }).then(response => {
            resolve(response);
        }).catch(error => {
            reject(error);
        });
    });
}

/**
 * 构建修改用户手机号任务
 * @param mt
 * @param user
 * @param qs
 * @returns {Promise<any>}
 */
export function buildEditPhTask( mt, user, _this ){
    return new Promise(function(resolve, reject) {
        let headers = {};
        let url = "./kwp/kdi/vouer/" + user.phUuid;
        let data = {code: user.phCode,vou: "Mobile"};
        if( mt === "post" ){
            headers = {"Content-Type": "application/x-www-form-urlencoded"};
            url = "./kwp/kdi/user/" + user.uuid + "/vouer";
            data = _this.qs.stringify(data);
        }else if ( mt === "put" ) {
            headers = {"Content-Type": "application/json;charset=UTF-8"};
        }else if ( mt === "delete" ) {
            headers = {};
        }else{
            return;
        }
        _this.axios.request({
            method: mt,
            url: url,
            headers: headers,
            data: data
        }).then(response => {
            resolve(response);
        }).catch(error => {
            reject(error);
        });
    });
}